package com.zhang.auth.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @Package: com.zhang.auth.service
 * @ClassName: MyUserDetailsService
 * @Author: Think
 * @CreateTime: 2021/8/3 15:27
 * @Description:
 */
@Service
public class MyUserDetailsService implements UserDetailsService {
    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return User
                .withUsername("zhangxun")
                .password(passwordEncoder.encode("mm123"))
                // 设置当前用户可以拥有的权限信息
                .authorities("user:query")
                .build();
    }
}
